package com.lsw.jgyf.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lsw.Base.BaseHolder;
import com.lsw.Base.BaseSimpleAdapter;
import com.lsw.jgyf.R;
import com.lsw.jgyf.model.PhoneModel;
import com.lsw.jgyf.util.GlideUtils;

/**
 * Created by lsw on 2018/7/9.
 */

public class HomeFragment2Adapter extends BaseSimpleAdapter<PhoneModel.DataEntity> {
    public HomeFragment2Adapter(Context context) {
        super(context);
    }

    @Override
    protected BaseHolder<PhoneModel.DataEntity> getHolder() {
        return new BaseHolder<PhoneModel.DataEntity>() {
            ImageView image;
            ImageView iv_heyueji;
            TextView tv_name;
            TextView tv_guige;
            TextView tv_price;

            @Override
            public void bindViews(View parentView) {
                image = parentView.findViewById(R.id.image);
                iv_heyueji = parentView.findViewById(R.id.iv_heyueji);
                tv_name = parentView.findViewById(R.id.tv_name);
                tv_guige = parentView.findViewById(R.id.tv_guige);
                tv_price = parentView.findViewById(R.id.tv_price);

            }

            @Override
            public void bindData(PhoneModel.DataEntity item, int position) {
                GlideUtils.loadImageView(context, item.getImg_url(), image);
                tv_name.setText(item.getPhoneBrand().getName() + item.getName());
                tv_guige.setText(item.getPhoneSku().getMemory() + " " + item.getPhoneSku().getColor() + " ");
                tv_price.setText(item.getPhoneSku().getPrice());
                if (item.getIs_contract() == 1) {
                    iv_heyueji.setVisibility(View.VISIBLE);
                } else {
                    iv_heyueji.setVisibility(View.INVISIBLE);
                }
            }
        };
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.item_homefragment2;
    }
}
